<?php

require_once 'PHPUnit/Extensions/OutputTestCase.php';
require_once 'Inspekt.php';

class Inspekt_Errors extends PHPUnit_Extensions_OutputTestCase {

    public function testIsHostnameIllegalValueNotInt() {
        $this->expectOutputRegex('/expected an integer/');
        try {
            Inspekt::isHostname( 'anything', 'not an integer' );
        }
        catch ( Exception $e ) {
            echo $e->getMessage();
        }
    }

    public function testIsHostnameIllegalValueIntOutOfBounds() {
        $this->expectOutputRegex('/expected integer between/');
        try {
            Inspekt::isHostname( 'anything', -1 );
        }
        catch ( Exception $e ) {
            echo $e->getMessage();
        }
    }

    public function testIsPhone() {
        $this->expectOutputRegex('/does not yet support this country/');
        try {
            // BBC complaint line (non-US #s not implemented in Inspekt):
            Inspekt::isPhone( '08700100222', 'UK' );
        }
        catch ( Exception $e ) {
            echo $e->getMessage();
        }
    }

    public function testIsUriAbsolute() {
        $this->expectOutputRegex('/has not been implemented/');
        try {
            Inspekt::isUri( 'anything', ISPK_URI_ALLOW_ABSOLUTE );
        }
        catch ( Exception $e ) {
            echo $e->getMessage();
        }
    }

    public function testWalkArrayNotAnArray() {
        $this->expectOutputRegex('/must be an array/');
        try {
            Inspekt::_walkArray( 'this is not an array',
                'this is not a method' );
        }
        catch ( Exception $e ) {
            echo $e->getMessage();
        }
    }

    public function testWalkArrayNotAMethod() {
        $this->expectOutputRegex('/ is invalid\z/');
        try {
            Inspekt::_walkArray( array(), 'this is not a method' );
        }
        catch ( Exception $e ) {
            echo $e->getMessage();
        }
    }

    public function testMakeSessionCage() {
        $this->expectOutputRegex('/disabled in this version/');
        try {
            Inspekt::makeSessionCage();
        }
        catch ( Exception $e ) {
            echo $e->getMessage();
        }
    }

}
